package rad.framework.uml2.classdiagram.edit.policies;

import rad.framework.uml2.classdiagram.providers.UMLElementTypes;
import rad.framework.uml2.classdiagram.util.ModelUtil;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gef.commands.Command;
import org.eclipse.gmf.runtime.emf.type.core.commands.CreateElementCommand;
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.uml2.uml.Operation;
import org.eclipse.uml2.uml.UMLPackage;

/**
 * @generated
 */
public class InterfaceOperationsItemSemanticEditPolicy extends
		UMLBaseItemSemanticEditPolicy {

	/**
	 * @generated
	 */
	protected Command getCreateCommand(CreateElementRequest req) {
		if (UMLElementTypes.Operation_2003 == req.getElementType()) {
			if (req.getContainmentFeature() == null) {
				req.setContainmentFeature(UMLPackage.eINSTANCE
						.getInterface_OwnedOperation());
			}
			return getMSLWrapper(new CreateOperation_2003Command(req));
		}
		return super.getCreateCommand(req);
	}

	/**
	 * @generated
	 */
	private static class CreateOperation_2003Command extends
			CreateElementCommand {

		/**
		 * @generated
		 */
		public CreateOperation_2003Command(CreateElementRequest req) {
			super(req);
		}

		/**
		 * @generated
		 */
		protected EClass getEClassToEdit() {
			return UMLPackage.eINSTANCE.getInterface();
		};

		/**
		 * @generated
		 */
		protected EObject getElementToEdit() {
			EObject container = ((CreateElementRequest) getRequest())
					.getContainer();
			if (container instanceof View) {
				container = ((View) container).getElement();
			}
			return container;
		}
		
		protected EObject doDefaultElementCreation() {
			Operation element = (Operation) super.doDefaultElementCreation();
			ModelUtil.applyStereotype(element, ModelUtil.WEBMETHOD);
			return element;
		}
	}

}
